﻿// Bing Maps ASP.NEt Control is a community project available under the Microsoft Public License (Ms-PL)
// Code is provided as is and with no warrenty – Use at your own risk
// View the project and the latest code at http://BingMapsASP.codeplex.com

using System.Collections.Generic;
using System.ComponentModel;
using System.Web.UI;
using Microsoft.Live.ServerControls.VE.Constants;

[assembly: WebResource("Microsoft.Live.ServerControls.VE.Extenders.Traffic.js", "text/javascript")]
[assembly: WebResource("Microsoft.Live.ServerControls.VE.Extenders.Traffic.debug.js", "text/javascript")]

namespace Microsoft.Live.ServerControls.VE.Extenders
{
    [ToolboxData(@"<{0}:Traffic ID=""TrafficExtender1"" runat=""server"" MapControlID="""" TargetControlID="""" ></{0}:Traffic>")]
    public sealed class Traffic : ExtenderBase
    {

        #region Properties

        /// <summary>
        /// Specifies the text shown with the traffic legend, if visible
        /// </summary>
        [Browsable(true)]
        [Category("Behaviour")]
        [DefaultValue("")]
        [Description("Specifies the text shown with the traffic legend, if visible")]
        public string TrafficLegendText
        {
            get { return (string)ViewState[TrafficExtenderControlProperty.TrafficLegendText] ?? string.Empty; }
            set { ViewState[TrafficExtenderControlProperty.TrafficLegendText] = value; }
        }

        /// <summary>
        /// The extender will toggle traffic on and off
        /// </summary>
        [Browsable(true)]
        [Category("Behaviour")]
        [DefaultValue("false")]
        [Description("The extender will toggle traffic on and off")]
        public bool ToggleTraffic
        {
            get { return (bool)(ViewState[TrafficExtenderControlProperty.ToggleTraffic] ?? false); }
            set { ViewState[TrafficExtenderControlProperty.ToggleTraffic] = value; }
        }

        /// <summary>
        /// The extender will toggle traffic legend on and off
        /// </summary>
        [Browsable(true)]
        [Category("Behaviour")]
        [DefaultValue("false")]
        [Description("The extender will toggle traffic on and off")]
        public bool ToggleTrafficLegend
        {
            get { return (bool)(ViewState[TrafficExtenderControlProperty.ToggleTrafficLegend] ?? false); }
            set { ViewState[TrafficExtenderControlProperty.ToggleTrafficLegend] = value; }
        }

        /// <summary>
        /// The extender will turn traffic on
        /// </summary>
        [Browsable(true)]
        [Category("Behaviour")]
        [DefaultValue("false")]
        [Description("The extender will turn traffic on")]
        public bool ShowTraffic
        {
            get { return (bool)(ViewState[TrafficExtenderControlProperty.ShowTraffic] ?? false); }
            set { ViewState[TrafficExtenderControlProperty.ShowTraffic] = value; }
        }

        /// <summary>
        /// The extender will turn traffic off
        /// </summary>
        [Browsable(true)]
        [Category("Behaviour")]
        [DefaultValue("false")]
        [Description("The extender will turn traffic off")]
        public bool HideTraffic
        {
            get { return (bool)(ViewState[TrafficExtenderControlProperty.HideTraffic] ?? false); }
            set { ViewState[TrafficExtenderControlProperty.HideTraffic] = value; }
        }

        /// <summary>
        /// The extender will turn traffic legend on
        /// </summary>
        [Browsable(true)]
        [Category("Behaviour")]
        [DefaultValue("false")]
        [Description("The extender will turn traffic legend on")]
        public bool ShowTrafficLegend
        {
            get { return (bool)(ViewState[TrafficExtenderControlProperty.ShowTrafficLegend] ?? false); }
            set { ViewState[TrafficExtenderControlProperty.ShowTrafficLegend] = value; }
        }

        /// <summary>
        /// The extender will turn traffic legend off
        /// </summary>
        [Browsable(true)]
        [Category("Behaviour")]
        [DefaultValue("false")]
        [Description("The extender will turn traffic legend off")]
        public bool HideTrafficLegend
        {
            get { return (bool)(ViewState[TrafficExtenderControlProperty.HideTrafficLegend] ?? false); }
            set { ViewState[TrafficExtenderControlProperty.HideTrafficLegend] = value; }
        }

        #endregion

        #region ExtenderControl Members

        protected override IEnumerable<ScriptDescriptor> GetScriptDescriptors(Control targetControl)
        {
            ScriptBehaviorDescriptor descriptor = new ScriptBehaviorDescriptor("Microsoft.Live.ClientControls.VE.Extenders.Traffic", targetControl.ClientID);
            descriptor.AddProperty(TrafficExtenderControlProperty.TrafficLegendText, TrafficLegendText);
            descriptor.AddProperty(TrafficExtenderControlProperty.ToggleTraffic, ToggleTraffic);
            descriptor.AddProperty(TrafficExtenderControlProperty.ToggleTrafficLegend, ToggleTrafficLegend);
            descriptor.AddProperty(TrafficExtenderControlProperty.ShowTraffic, ShowTraffic);
            descriptor.AddProperty(TrafficExtenderControlProperty.HideTraffic, HideTraffic);
            descriptor.AddProperty(TrafficExtenderControlProperty.ShowTrafficLegend, ShowTrafficLegend);
            descriptor.AddProperty(TrafficExtenderControlProperty.HideTrafficLegend, HideTrafficLegend);
            descriptor.AddProperty(ExtenderControlProperty.MapControlID, MapControlID);
            yield return descriptor;
        }

        protected override IEnumerable<ScriptReference> GetScriptReferences()
        {
            List<ScriptReference> descriptors = new List<ScriptReference>();
            descriptors.Add(new ScriptReference("Microsoft.Live.ServerControls.VE.Extenders.Traffic.js", GetType().Assembly.FullName));
            return descriptors;
        }

        #endregion
    }
}
